package com.ztgf.user.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.ztgf.user.models.vo.UserRoleRelationVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import javax.annotation.Resource;
import com.ztgf.user.common.config.YmlConfig;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ztgf.user.mapper.UserRoleRelationMapper;
import com.ztgf.user.models.service.IUserRoleRelationService;
import com.ztgf.user.models.bo.UserRoleRelationSaveBO;
import com.ztgf.user.models.dto.UserRoleRelationDTO;

import java.util.List;

/**
 * 用户角色关系表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 17:48:24
 */
@DubboService
public class UserRoleRelationServiceImpl extends ServiceImpl<UserRoleRelationMapper, UserRoleRelationDTO> implements IUserRoleRelationService{

    @Resource
    private YmlConfig ymlConfig;

    /**
     * 根据用户id获取权限id集合
     * @param userId
     * @return
     */
    @Override
    public List<Long> getRoleIdListByUserId(Long userId){
        return baseMapper.getRoleIdListByUserId(userId);
    }

    @Override
    public boolean add(UserRoleRelationSaveBO saveBO) {
        UserRoleRelationDTO dto = new UserRoleRelationDTO();
        BeanUtils.copyProperties(saveBO,dto);
        Long id = ymlConfig.getPkId();
        dto.setId(id);
        return this.insert(dto);
    }

    @Override
    public List<UserRoleRelationDTO> queryListByUserId(Long userId) {
        Wrapper<UserRoleRelationDTO> wrapper = new EntityWrapper<>();
        wrapper.eq("user_id", userId);
        return this.selectList(wrapper);
    }

    @Override
    public List<UserRoleRelationVO> queryRoleListByUserId(Long userId) {
        return baseMapper.queryRoleListByUserId(userId);
    }

    @Override
    public boolean deleteByUserid(Long userId) {
        return baseMapper.deleteByUserid(userId);
    }
}
